package org.neframework.webtest.action.system;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.model.t_fk_setting;
import org.neframework.webtest.model.t_fk_ui;
import org.neframework.webtest.service.SystemService;

import org.neframework.webtest.base.BaseController;
import com.tmsps.neframework.core.utils.JsonTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;
import com.tmsps.neframework.mvc.plugin.Tip;

@Controller
@RequestMapping("/cp/system")
public class SystemController extends BaseController {

	private static final SystemService sysService = new SystemService();
	
	@RequestMapping("/list")
	public String list() {
		return "/jsp/system/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data() {

		List<Map<String, Object>> list = sysService.selectSystemList();

		result.put("list", list);
	}

	@RequestMapping("/add")
	@ResponseBody
	public void add(t_fk_setting set) {
		oc.saveObj(set);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/edit_form")
	@ResponseBody
	public String edit_form(String kid) {
		t_fk_setting set = (t_fk_setting) oc.findObjById(kid, t_fk_setting.class);
		return JsonTools.toJson("set", set);
	}

	@RequestMapping("/edit")
	@ResponseBody
	public void edit(t_fk_setting set) {
		t_fk_setting setDb = (t_fk_setting) oc.findObjById(set.getKid(), t_fk_setting.class);
		setDb.setField(set.getField());
		setDb.setVal(set.getVal());
		setDb.setNote(set.getNote());
		oc.updateObj(setDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/del")
	@ResponseBody
	public void del(String kid) {
		oc.delObjById(kid, t_fk_setting.class);

		this.setTipMsg(true, "删除成功!", Tip.Type.success);
	}
	
	/**
	 *去向ui页面 
	 * @return
	 */
	
	@RequestMapping("/listui")
	public String listUi() {
		return "/jsp/system/ui/list.jsp";
	}
	
	/**
	 *系统ui列表 
	 */
	@RequestMapping("/list_ui")
	@ResponseBody
	public void list_ui() {

		List<Map<String, Object>> list = sysService.selectSystemUiList();

		result.put("list", list);
	}
	
	/**
	 *删除ui 
	 */
	@RequestMapping("/del_ui")
	@ResponseBody
	public void del_ui(String kid) {

		oc.delObjById(kid,t_fk_ui.class);

		super.setTipMsg("删除成功", Tip.Type .success);
	}
	
	/**
	 *添加ui 
	 */
	@RequestMapping("/add_ui")
	@ResponseBody
	public void add_ui(t_fk_ui ui) {

		oc.saveObj(ui);

		super.setTipMsg("添加成功", Tip.Type .success);
	}
	
	/**
	 *ui修改
	 */
	@RequestMapping("/edit_form_ui")
	@ResponseBody
	public String edit_form_ui(String kid) {
		t_fk_ui ui = (t_fk_ui) oc.findObjById(kid, t_fk_ui.class);
		return JsonTools.toJson("ui", ui);
	}

	@RequestMapping("/editui")
	@ResponseBody
	public void editui(t_fk_ui ui) {
		
		t_fk_ui uiDb = (t_fk_ui) oc.findObjById(ui.getKid(), t_fk_ui.class);
		uiDb.setBackgroud_file_id(ui.getBackgroud_file_id());
		uiDb.setLogo_file_id(ui.getLogo_file_id());
		uiDb.setName(ui.getName());
		uiDb.setMenu_position(ui.getMenu_position());
		oc.updateObj(uiDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

}
